import type { RequiredDeep } from 'type-fest'

import { ajax } from '@/utils'

import type { components } from '../schema'
import type { IDeleteReq, IExportRes } from '../type'

/**
 * 岗位接口
 */
export const postApi = {
  /**
   * 获取岗位分页
   */
  getPostPage(data: IGetPostPageReq): Promise<IGetPostPageRes> {
    return ajax.post('/system/post/page', data)
  },
  /**
   * 添加岗位
   */
  createPost(data: ICreatePostReq) {
    return ajax.post('/system/post/create', data)
  },
  /**
   * 更新岗位
   */
  updatePost(id: string, data: IUpdatePostReq) {
    return ajax.put('/system/post/update', data, { params: { id } })
  },
  /**
   * 删除岗位
   */
  deletePost(data: IDeleteReq) {
    return ajax.delete('/system/post/delete', { data })
  },
  /**
   * 导出岗位分页
   */
  exportPostPage(data: IGetPostPageReq): Promise<IExportRes> {
    return ajax.post('/system/post/export', data)
  }
}

export type IGetPostPageReq = components['schemas']['FindPostPageDTO']
export type IGetPostPageRes = RequiredDeep<
  components['schemas']['FindPostPageVO']['data']
>
export type IPostPageItem = IGetPostPageRes['list'][0]
export type ICreatePostReq = components['schemas']['CreatePostDTO']
export type IUpdatePostReq = components['schemas']['UpdatePostDTO']
